home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / Samples / Moofwars 1.02 / Tim's Libraries / TGraphicCollection.h < prev   
Encoding:
C/C++ Source or Header  |  1997-11-05  |  4.5 KB  |  129 lines  |  [TEXT/CWIE]

  1. /*****************************************************************************
  2. TGraphicCollection.h
  3.  
  4. Author: Timothy Carroll
  5. Apple Developer Technical Support
  6. timc@apple.com
  7.  
  8. Copyright © 1996, 1997 Apple Computer, Inc., All Rights Reserved
  9.  
  10. You may incorporate this sample code into your applications without
  11. restriction, though the sample code has been provided "AS IS" and the
  12. responsibility for its operation is 100% yours.  However, what you are
  13. not permitted to do is to redistribute the source as "DSC Sample Code"
  14. after having made changes. If you're going to re-distribute the source,
  15. we require that you make it clear in the source that the code was
  16. descended from Apple Sample Code, but that you've made changes.
  17.  
  18. See TGraphicCollection.cp for description and the list of changes.
  19.  
  20. *****************************************************************************/
  21.  
  22. #ifndef _TGRAPHICCOLLECTION_
  23. #define _TGRAPHICCOLLECTION_
  24.  
  25. #pragma once
  26.  
  27. #include "TGraphic.h"
  28.  
  29. #if PRAGMA_STRUCT_ALIGN
  30. #pragma options align=power
  31. #endif
  32.  
  33.  
  34. class TGraphicCollection
  35. {
  36.     public:
  37.     
  38. /*****************************************************************************
  39. Static Creator and Reference Counting
  40.  
  41. These are the routines that handle the actual creation of the objects, along
  42. with reference counting and so on.  You don't dispose of an object directly,
  43. you just dispose of your reference.  It will automatically be chucked out
  44. when all references are deleted.
  45.  
  46. A TGraphicCollection is defined by a resource of type 'SptA' or sprite array.
  47. *****************************************************************************/
  48.     static    TGraphicCollection     *NewCollection (SInt16 resID);
  49.  
  50.     void    AddReference (void);
  51.     void    DisposeReference (void);
  52.     
  53.     
  54.     
  55. /*****************************************************************************
  56. Locking and Unlocking
  57.     
  58. You are never required to lock a collection, but you can choose to lock them
  59. down high in memory to ensure that they don't move around when other, critical
  60. memory allocations are being done.
  61. *****************************************************************************/
  62.     OSStatus    LockCollection (void);
  63.     OSStatus    UnlockCollection (void);
  64.     
  65.     
  66. /*****************************************************************************
  67. Creating and destroying the collection
  68.  
  69. The actual work to load by CreateCollection.  DisposeCollection releases any
  70. references to the list of TGraphics and disposes any additional memory we
  71. may have allocated.
  72. *****************************************************************************/
  73.     OSStatus    CreateCollection (void);
  74.     OSStatus    DestroyCollection (void);
  75.     
  76.     
  77. /*****************************************************************************
  78. Accessor Functions
  79.  
  80. We actually do allow a client to obtain a TGraphic directly.  An immediate
  81. link is not made when this is done.  Clients should assume the TGraphic will
  82. be available through the current scope, and if you need it longer than that,
  83. you should explicitly create a reference to it.
  84. *****************************************************************************/
  85.  
  86.     SInt16            GetResID(void) {return fResID;}
  87.     Rect            GetBounds (UInt32 index);
  88.     TGraphic        *GetTGraphic (UInt32 index); // returns a naked TGraphic.  Use sparingly.
  89.     
  90.     
  91. /*****************************************************************************
  92. Utility Functions
  93.  
  94. These just call through to the equivalent TGraphic classes.
  95. *****************************************************************************/
  96.     void            CopyImage (UInt32 index, SInt32 top, SInt32 left, Boolean useBackground);                                   
  97.     Boolean            HitTest (UInt32 index, SInt32 v, SInt32 h);
  98.     
  99.  
  100. protected:
  101.         
  102. /*****************************************************************************
  103. Constructor/Destructor
  104.     
  105. The contructor and destructor are only called internally by the class.  Clients
  106. should ask for an object via its resource ID, using the static routine above.
  107. *****************************************************************************/
  108.     TGraphicCollection (SInt16 resID);
  109.     ~TGraphicCollection (void);
  110.  
  111.     
  112. /*****************************************************************************
  113. Data Structures
  114.     
  115. The actual data used to hold the TGraphicCollection.  The structs could use
  116. either 68K or PowerPC alignment (they come out the same).
  117. *****************************************************************************/
  118.  
  119.     Handle            fGraphics;           // 4 bytes
  120.     SInt16            fResID;            // 2 bytes
  121.     UInt16            fReferenceCount;   // 2 bytes, # of owners of this collection;
  122.     UInt32            fNumberOfGraphics; // 4 bytes
  123. };
  124.  
  125. #if PRAGMA_STRUCT_ALIGN
  126. #pragma options align=reset
  127. #endif
  128.  
  129. #endif /* _TGRAPHICCOLLECTION_ */